home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1997 October / macformat-055.iso / mac / Shareware Plus / System Components / Smart Scroll 2.03 / for Developers / SmartScrollAPI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-21  |  4.4 KB  |  131 lines  |  [TEXT/CWIE]

  1. /*
  2.      File:        SmartScrollAPI.c
  3.  
  4.      Contains:    Smart Scroll Application Programming Interface code
  5.  
  6.      Version:    1.3
  7.  
  8.      Copyright:    © 1996, 1997 by Marc Moini, portions by Marc Menschenfreund,
  9.                 Alessandro Levi Montalcini and Mark Shirley (Thanks!)
  10.                  All rights reserved.
  11.  
  12.      Bugs?:        If you find a problem with this file, please email Marc@Kagi.com
  13.  
  14.      Version
  15.     History:    1.3        21feb97    Same as 1.2, except a couple of "ControlHandle" definitions changed to "ControlRef"
  16. */
  17.  
  18. #ifndef __SMARTSCROLLAPI__
  19. #include "SmartScrollAPI.h"
  20. #endif
  21.  
  22. #if PRAGMA_ALIGN_SUPPORTED
  23. #pragma options align=mac68k
  24. #endif
  25.  
  26. #if PRAGMA_IMPORT_SUPPORTED
  27. #pragma import on
  28. #endif
  29.  
  30. #define    kgestaltSmartScroll    'MMBS'
  31.  
  32. enum
  33.     {
  34.     kSetSmartScrollInfo = 0L,
  35.     kSetSmartScrollProp,
  36.     kGetSmartScrollProp,
  37.     kDisposeAllSmartScrolls
  38.     };
  39.  
  40. typedef pascal void (*SmartScrollProcPtr) (long selector,long *result,ControlRef theScrollBar,long param1,long param2);
  41.  
  42. typedef struct {
  43.     char                privateStuff[16];
  44.     SmartScrollProcPtr    dispatchProc;
  45.     long                smartScrollSignature;
  46. } SmartScrollGestaltRec, *SmartScrollGestaltPtr;
  47.  
  48.  
  49. #if GENERATINGCFM
  50. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  51.         CallUniversalProc((UniversalProcPtr)(userRoutine), uppSmartScrollProcInfo, (selector), (result), (theControl), (param1), (param2))
  52. #else
  53. #define CallSmartScrollProc(userRoutine, selector, result, theControl, param1, param2)        \
  54.         (*(userRoutine))((selector), (result), (theControl), (param1), (param2))
  55. #endif
  56.  
  57. enum    {
  58.     uppSmartScrollProcInfo = kPascalStackBased
  59.         | STACK_ROUTINE_PARAMETER (1, SIZE_CODE(sizeof(long)))
  60.         | STACK_ROUTINE_PARAMETER (2, SIZE_CODE(sizeof(long *)))
  61.         | STACK_ROUTINE_PARAMETER (3, SIZE_CODE(sizeof(ControlRef)))
  62.         | STACK_ROUTINE_PARAMETER (4, SIZE_CODE(sizeof(long)))
  63.         | STACK_ROUTINE_PARAMETER (5, SIZE_CODE(sizeof(long)))
  64. };
  65. /****************************************************************************************/
  66.  
  67. static OSErr __SmartScrollDispatch(long selector,long *result,ControlRef theControl,long param1,long param2)
  68.     {
  69.     OSErr                     ret = paramErr;
  70.     SmartScrollGestaltPtr    ssRec;
  71.     
  72.     if (NGetTrapAddress (_Gestalt, OSTrap) != NGetTrapAddress (_Unimplemented, OSTrap))
  73.         {
  74.         if (Gestalt ( kgestaltSmartScroll, (long *)&ssRec)==noErr
  75.             && ssRec && ssRec->smartScrollSignature==kgestaltSmartScroll)
  76.             {
  77.                 CallSmartScrollProc(ssRec->dispatchProc,selector,result,theControl,param1,param2);
  78.                 ret = noErr;
  79.             }
  80.         }
  81.     return ret;
  82.     }
  83.     
  84. /****************************************************************************************/
  85. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  86. /*  amountVisible is a 32bit value representing the size of the portion of the document that is visible now. */
  87. /*  amountTotal is a 32bit value representing the size of the whole document. */
  88. /*  these two parameters must share the same unit (pixels, lines, characters, frames, etc). */
  89.  
  90. pascal void SetSmartScrollInfo (ControlRef theScrollBar, long amountVisible , long amountTotal)
  91.     {
  92.     long     dummy;
  93.     
  94.     (void)__SmartScrollDispatch(kSetSmartScrollInfo,&dummy,theScrollBar,amountVisible,amountTotal);
  95.     }
  96.  
  97. /****************************************************************************************/
  98. /* Call this routine to set the Visible/Total proportion for a scrollbar. */
  99. /*  proportion is a Fract value (32bit) representing the Visible/Total ratio */
  100. /*  This call has the exact same effect as SetSmartScrollInfo, you may use either one. */
  101.  
  102. pascal void SetSmartScrollProp (ControlHandle theScrollBar, Fract proportion)
  103.     {
  104.     long     dummy;
  105.     
  106.     (void)__SmartScrollDispatch(kSetSmartScrollProp,&dummy,theScrollBar,(long)proportion,0);
  107.     }
  108.  
  109. /****************************************************************************************/
  110. /* Call this routine to get the last proportion you stored for this scrollbar. */
  111. /* the value returned will be 0 if there is an error (Smart Scroll not installed, or no value stored)  */
  112.  
  113. pascal Fract GetSmartScrollProp (ControlHandle theScrollBar)
  114.     {
  115.     Fract     result = 0L;
  116.     
  117.     __SmartScrollDispatch(kGetSmartScrollProp,(long *)&result,theScrollBar,0,0);
  118.     return result;
  119.     }
  120.  
  121. /****************************************************************************************/
  122. /* Call this routine before your code Quits, to help SmartScroll */
  123. /* free the memory it reserved for the scrollbars in your Application. */
  124.  
  125. pascal void DisposeAllSmartScrolls (void)
  126.     {
  127.     long     dummy;
  128.     
  129.     (void)__SmartScrollDispatch(kDisposeAllSmartScrolls,&dummy,NULL,0,0);
  130.     }
  131.